import Vue from 'vue'
import App from './App.vue'

// 导入 Element_ui
import ElementUI from 'element-ui'
// 导入 Element-ui 样式
import 'element-ui/lib/theme-chalk/index.css'
// 插件 Element-ui
Vue.use(ElementUI)

// vuex
import Vuex from 'vuex'
Vue.use(Vuex)

import store from './store'

// 导入全局初始化样式
import './assets/index.css'

// import axios from 'axios'
// //配置请求根路径
// axios.defaults.baseURL = 'https://cloud-music-serve-1.vercel.app/'
// Vue.prototype.$http = axios

// Aplayer播放插件
import APlayer from '@moefe/vue-aplayer';

Vue.use(APlayer, {
  defaultCover: 'https://github.com/u3u.png',
  productionTip: true,
});

// 路由整合
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// 导入对应的路由
import discovery from './views/01.discovery.vue'
import playlists from './views/02.playlists.vue'
import songs from './views/03.songs.vue'
import mvs from './views/04.mvs.vue'
import result from './views/05.result.vue'
import playlist from './views/06.playlist.vue'
import mv from './views/07.mv.vue'
// import Router from 'vue-router'

// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }


const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/discovery'
    },
    {
      // 发现音乐
      path: '/discovery',
      component: discovery
    },
    {
      // 推荐歌单
      path: '/playlists',
      component: playlists
    },
    {
      // 推荐歌单
      path: '/playlist',
      component: playlist
    },
    {
      // 最新音乐
      path: '/songs',
      component: songs
    },
    {
      // 最新音乐
      path: '/mvs',
      component: mvs
    },
    // mv详情
    {
      path: '/mv',
      component: mv
    },
    // 搜索结果页
    {
      path: '/result',
      component: result
    }
  ]
})

Vue.config.productionTip = false

Vue.filter('dateFormat', function (times) {
  function padZero(n) {
    return n < 10 ? '0' + n : n
  }
  let min = padZero(parseInt(times / 1000 / 60))
  let sec = padZero(parseInt(times / 1000 % 60))
  return `${min}:${sec}`
})

Vue.filter('countFormat', function (count) {
  if (count >= 100000) {
    return `${parseInt(count / 10000)}万`
  } else {
    return count
  }
})

Vue.filter('timeFormat', function (time) {
  var date = new Date(time)
  var y = date.getFullYear()// 年份
  var m = (date.getMonth() + 1 + '').padStart('2',0) // 月份
  var d = (date.getDate() + '').padStart('2',0) // 日
  var hh = (date.getHours() + '').padStart('2',0) // 小时
  var mm = (date.getMinutes() + '').padStart('2',0) // 分钟
  var ss = (date.getSeconds() + '').padStart('2',0) // 秒
  // 返回值，根据自己需求调整，现在已经拿到了年月日时分秒了
  return y + '-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss
})

const vm = new Vue({
  render: h => h(App),
  // 挂载到Vue示例上
  router,
  store,
  beforeCreate() {
    Vue.prototype.$bus = this
  },
}).$mount('#app')
console.log(vm);

